package lc_剑指_Offer_II_083_没有重复元素集合的全排列;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class Solution {
	int n;
	List<List<Integer>> ans;

	public List<List<Integer>> permute(int[] nums) {
		n = nums.length;
		this.ans = new ArrayList<>();
		List<Integer> list = Arrays.stream(nums).boxed().collect(Collectors.toList());
		f(0, list);
		return this.ans;
	}

	public void f(int id, List<Integer> list) {
		if (id == n) {
			this.ans.add(new ArrayList<>(list));
			return;
		}
		for (int i = id; i < n; i++) {
			Collections.swap(list, id, i);
			f(id + 1, list);
			Collections.swap(list, id, i);
		}
	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.permute(new int[] { 1, 1, 2 });
	}

}